package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.hr.dto.ApplyToProgPositionAddDTO;
import org.jsola.hr.dto.ApplyToProgPositionUpdateDTO;
import org.jsola.hr.entity.ApplyToProgPositionDO;
import org.jsola.hr.query.ApplyToProgPositionQuery;
import org.jsola.hr.service.IApplyToProgPositionService;
import org.jsola.hr.vo.ApplyToProgPositionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class ApplyToProgPositionTestHelper extends BaseTestHelper {
    
    @Autowired
    private IApplyToProgPositionService applyToProgPositionService;

    /**
     * 生成add测试数据
     * @return ApplyToProgPositionAddDTO
     */
    public ApplyToProgPositionAddDTO getApplyToProgPositionAddDTO(){
        ApplyToProgPositionAddDTO applyToProgPositionAddDTO = new ApplyToProgPositionAddDTO();
        applyToProgPositionAddDTO.setProgId(getRandomValue("varchar",32));
        applyToProgPositionAddDTO.setPositionId(getRandomValue("varchar",32));
        applyToProgPositionAddDTO.setCompanyId(getRandomValue("varchar",32));
        return applyToProgPositionAddDTO;
    }


    /**
     * 生成update测试数据
     * @return ApplyToProgPositionUpdateDTO
     */
    public ApplyToProgPositionUpdateDTO getApplyToProgPositionUpdateDTO(ApplyToProgPositionVO applyToProgPositionVO){
        return applyToProgPositionService.selectDOById(applyToProgPositionVO.getId(), SITE_ID).to(ApplyToProgPositionUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return ApplyToProgPositionQuery
     */
    public ApplyToProgPositionQuery getApplyToProgPositionQuery() {
        ApplyToProgPositionQuery applyToProgPositionQuery = new ApplyToProgPositionQuery();
        List<ApplyToProgPositionDO> applyToProgPositionDOList = applyToProgPositionService.list(new ApplyToProgPositionDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(applyToProgPositionDOList)) {
            ApplyToProgPositionDO applyToProgPositionDO = applyToProgPositionDOList.get(0);
            applyToProgPositionQuery = applyToProgPositionDO.to(ApplyToProgPositionQuery.class);
            if (applyToProgPositionDO.getGmtCreate() != null) {
                applyToProgPositionQuery.setGmtCreateStart(DateKit.getBeforeDay(applyToProgPositionDO.getGmtCreate(),-1));
                applyToProgPositionQuery.setGmtCreateEnd(DateKit.getBeforeDay(applyToProgPositionDO.getGmtCreate(),1));
            }
        }
        return applyToProgPositionQuery;
    }

    /**
     * 保存示例
     * @return ApplyToProgPositionVO
     */
    public ApplyToProgPositionVO saveApplyToProgPositionExample(){
        ApplyToProgPositionAddDTO addDTO = this.getApplyToProgPositionAddDTO();
        ApplyToProgPositionVO applyToProgPositionVO = applyToProgPositionService.save(addDTO,buildTokenUser());
        return applyToProgPositionVO;
    }


}

